﻿using System;
using System.Collections.Generic;

namespace My.Blog.Web
{
    public class BlogUI
    {
        /// <summary>
        /// Index
        /// </summary>
        /// <returns></returns>
        public static string Index()
        {
            BlogSystem bs = new BlogSystem();
            List<MyBlog> list = bs.GetBlogs();
            if(0 == list.Count)
            {
                return "<p>抱歉！没有找到您要找的东西！</p>";
            }

            List<string> ret = new List<string>();
            foreach (MyBlog blog in list)
            {
                ret.Add(
                    string.Format("<a href='Default.aspx?Module=Blog&Action=Index&Id={0}'>{1}</a>"
                    , blog.Id
                    , blog.Name));
            }
            return string.Join("\r\n",ret.ToArray());
        }

        /// <summary>
        /// New
        /// </summary>
        /// <returns></returns>
        public static string New()
        {
            return @"
    <dl>
        <dt>Name:</dt>
        <dd><input type='text' name='Name' /></dd>

        <dt>Owner:</dt>
        <dd><input type='text' name='Owner' /></dd>

        <dt>Introduction:</dt>
        <dd><input type='text' name='Introduction' /></dd>

        <dt>Declaration:</dt>
        <dd><input type='text' name='Declaration' /></dd>

        <dt>IsPublished:</dt>
        <dd>
            <select name='IsPublished'><option value='true'>是</option>
                                       <option value='false'>否</option>
            </select>
        </dd>

        <dt></dt>
        <dd>
            <button>确定</button>
            <button class='cancel' onclick='return false;'>取消</button>
        </dd>
    </dl>";
        }


        public static string Details()
        {
            return @"
<h1>Blog详细</h1>
 
<!--<If:Empty>-->
    <p>抱歉！没有找到您要找的东西！</p>
<!--</If:Empty>-->

<!--<IfNot:Empty>-->
<!--<IfNot:Maintain>-->
    <div>
        <div>Id:{Id}</div>
        <div>DateCreated:{DateCreated}</div>
        <div>DateModified:{DateModified}</div>
        <div>UserCreated:{UserCreated}</div>
        <div>UserModified:{UserModified}</div>
        <div>Name:{Name}</div>
        <div>Owner:{Owner}</div>
        <div>Introduction:{Introduction}</div>
        <div>Declaration:{Declaration}</div>
    </div>
<!--</IfNot:Maintain>-->";
        }

        public static string Update()
        {
            return @"
<!--<If:Maintain>-->
<form id='FrmUpdateBlog' method='post' action='{RootUrl}/_Ajax/Blog.aspx?op=UpdateBlog'>    
    <h1>修改Blog</h1>
    <div>
        <input type='hidden' name='Id' value='{Id}' />
        Name:<input type='text' name='Name' value='{Name}' />
        Owner:<input type='text' name='Owner' value='{Owner}' />
        Introduction:<input type='text' name='Introduction' value='{Introduction}' />
        Declaration:<input type='text' name='Declaration' value='{Declaration}' />
        <button>提交</button>
    </div>
</form>
<script type='text/javascript'>
    $('#FrmUpdateBlog').ajaxSubmit( function(dat){
        $('body').alert(dat.response||dat.error||'');
    });
</script>  
<!--</If:Maintain>-->
<!--</IfNot:Empty>-->";
        }
    }
}